<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 16. Name generator</a><br />
<a href="namegen_init.html">&lt; 16.1 Creating a generator</a>
</td><td width="60%">
<p align="center">
=====================================<br />
16.2 Generating a name<br />
=====================================<br />
</p></td><td width="20%">
<a href="namegen_delete.html">&gt; 16.3 Destroying a generator</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
<h3>TCODNamegen::generate</h3>
The following will output a random name generated using one of the generation rules specified in the syllable set:<br />
<p class="code"><pre>
C++ : static char * TCODNamegen::generate(char * name, bool allocate = false)
C   : char * TCOD_namegen_generate(char * name, bool allocate);
Py  : namegen_generate(name, allocate=0)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>name</td><td>The structure name you wish to refer to, for instance, "celtic female".<br />For more about how structure names work, please refer to chapters <a href="namegen_file.html">16.5</a> and <a href="../parser/parser_format.html">7.1</a>.</td></tr>
<tr><td>allocate</td><td>Whether memory should be allocated for the output or not.</td></tr>
</table>
<br />
Should you choose to allocate memory for the output, you need to remember to deallocate it once you don't need the name anymore using the free() function. This applies to C++ as well (delete won't work - you have to use free()).<br />
<br />
On the other hand, should you choose not to allocate memory, be aware that subsequent calls will overwrite the previously returned pointer, so make sure to copy the output using strcpy(), strdup() or other means of your choosing.<br />
<br />
The name you specify needs to be in one of the files the generator has previously parsed (see <a href="namegen_init.html">TCODNamegen::parse</a>). If such a name doesn't exist, a warning will be displayed and NULL will be returned.<br />
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODNamegen::parse("data/names.txt",TCODRandom::getInstance());
      char * myName = TCODNamegen::generate("fantasy female");
C   : TCOD_namegen_parse("data/names.txt",TCOD_random_get_instance());
      char * my_name = TCOD_namegen_generate("Celtic male",false);
Py  : libtcod.namegen_parse('data/names.txt')
      name = libtcod.namegen_generate('fantasy female')
</pre></p>
<hr />
<h3>TCODNamegen::generateCustom</h3>
It is also possible to generate a name using custom generation rules. This overrides the random choice of a generation rule from the syllable set. Please refer to chapter <a href="namegen_file.html">16.5</a> to learn about the name generation rules syntax.<br />
<p class="code"><pre>
C++ : static char * TCODNamegen::generateCustom(char * name, char * rule, bool allocate = false)
C   : char * TCOD_namegen_generate_custom(char * name, char * rule, bool allocate);
Py  : namegen_generate_custom(name, rule, allocate=0)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>name</td><td>The structure name you wish to refer to, for instance, "celtic female".<br />For more about how structure names work, please refer to chapters <a href="namegen_file.html">16.5</a> and <a href="../parser/parser_format.html">7.1</a>.</td></tr>
<tr><td>rule</td><td>The name generation rule. See chapter <a href="namegen_file.html">16.5</a> for more details.</td></tr>
<tr><td>allocate</td><td>Whether memory should be allocated for the output or not.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODNamegen::create("data/names.txt",TCODRandom::getInstance());
      char * myName = TCODNamegen::generateCustom("Nordic male","$s$e");
C   : TCOD_namegen_new("data/names.txt",TCOD_random_get_instance());
      char * my_name = TCOD_namegen_generate_custom("Mesopotamian female","$s$e",false);
Py  : libtcod.namegen_parse('data/names.txt')
      name = libtcod.namegen_generate('fantasy female','$s$e')
</pre></p>
